import Paper from 'paper'

import SelectTool from './select'
import GridTool from './grid'
import LineTool, { PolyTool } from './line'
import RectTool from './rect'
import RectPointTool from './rectPoint1'

const Tools = {
  select: SelectTool,
  grid: GridTool,
  line: LineTool,
  poly: PolyTool,
  rect: RectTool,
  rectPoint1: RectPointTool,
}

// 根据名字创建 Tool
export const ToolFactory = (name, options) => {
  if (Tools[name]) {
    return Reflect.construct(Tools[name], [{ name, ...options }])
  } else {
    console.warn('Tool name error:', name)
    return new Paper.Tool({ name, ...options })
  }
}
